﻿Public Class frmTraCuuTheoGV

    Private Sub btnTHOAT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTHOAT.Click
        Me.Close()
    End Sub

    Private Sub frmTraCuuTheoGV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _gv As New DataTable
        _gv = GiaoVienDAO.SelectAll()
        cmbMAGV.DataSource = _gv
        cmbMAGV.DisplayMember = "HoTen"
        cmbMAGV.ValueMember = "MaGV"
        cmbMAGV.SelectedIndex = -1

        Dim _cm As New DataTable
        _cm = ChuyenMonDAO.SelectAll()
        cmbMACHUYENMON.DataSource = _cm
        cmbMACHUYENMON.DisplayMember = "TenChuyenMon"
        cmbMACHUYENMON.ValueMember = "MaChuyenMon"
        cmbMACHUYENMON.SelectedIndex = -1

    End Sub

    Private Sub btnTIM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTIM.Click
        Dim _maGV As Integer = cmbMAGV.SelectedValue
        Dim _maCM As Integer = cmbMACHUYENMON.SelectedValue

        Dim _strWhere As String = String.Empty

        If _maGV <> 0 Then
            _strWhere += " GV.MaGV like " & _maGV
        End If

        If _maCM <> 0 Then
            If Not String.IsNullOrEmpty(_strWhere) Then
                _strWhere += " and "
            End If
            _strWhere += " CM.MaChuyenMon like " & _maCM
        End If

        If Not String.IsNullOrEmpty(_strWhere) Then
            _strWhere = " and " & _strWhere
        End If

        Dim strSQL As String = "select GV.MaGV, GV.HoTen, PH.TenPhong, LH.TenLop, CM.TenChuyenMon from GIAOVIEN GV, LOPHOC LH, PHONGHOC PH, PHANCONG PC, CHUYENMON CM where GV.MaChuyenMon=CM.MaChuyenMon and GV.MaGV=PC.MaGV and PH.MaPhong=PC.MaPhong and PC.MaLop=LH.MaLop" & _strWhere
        Dim _tc As DataTable
        _tc = PhanCongDAO.SelectByGV(strSQL)
        dgvTCTheoGV.DataSource = _tc
    End Sub

    Private Sub btnIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIN.Click
        Dim _dt As New DataTable
        _dt.Clear()
        _dt = PhanCongDAO.SelectAll()
        dgvTCTheoGV.DataSource = _dt
        'Nap du lieu cho Report
        Dim myReport As New CR_TraCuuGV()
        myReport.SetDataSource(_dt.DataSet)
        'Nap form in report
        Dim f As New InTraCuuGV
        f.CRV_TraCuuGV.ReportSource = myReport
        f.ShowDialog()
    End Sub
End Class